<?php


namespace dsp\iterator;


class WordsCollection implements \IteratorAggregate
{

    private $items = [];

    public function getItems()
    {
        return $this->items;
    }

    public function addItem($item)
    {
        $this->items[] = $item;
    }

    public function getIterator()
    {
        echo '=========== 初始化迭代器1' . PHP_EOL;
        return new AlphabeticalOrderIterator($this);
    }

    public function getReverseIterator()
    {
        echo '=========== 初始化迭代器2' . PHP_EOL;
        return new AlphabeticalOrderIterator($this, true);
    }
}